package com.eascs.afterloan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.afterloan.form.RefundPrintForm;
import com.eascs.afterloan.service.RefundConCodeService;
import com.eascs.afterloan.service.RefundPrintService;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;

@RestController
public class RefundPrintRestController extends BaseRestController {
	
	@Autowired
	RefundPrintService service;
	
	@Autowired
	RefundConCodeService codeService;
	
	/**
	 * 打印代还款确认书
	 * 
	 * @param billCode
	 *            贷款编码
	 * @return
	 */
	@RequestMapping(value = "/refundPrint")
	public HtmlRestResult refundPrint(String billCode) {
		//根据billCode查询借款人姓名，证件类型，证件号码和合同编号
		RefundPrintForm entity = service.findByCode(billCode);
		//根据billCode查询带代还款编号
		String refundCode = codeService.generateRefundCode(billCode);
		
		ViewContext.put("vo", entity);
		ViewContext.put("code", refundCode);
		return HtmlRestResult.popHtmlFragment("afterloan/refund_print");
	}
	
	/**
	 * 打印付款确认书
	 * 
	 * @param billCode
	 *            贷款编码
	 * @return
	 */
	@RequestMapping(value = "/paymentPrint")
	public HtmlRestResult paymentPrint(String billCode) {
		// 根据billCode查询借款人姓名，证件类型，证件号码和合同编号
		RefundPrintForm entity = service.findByCode(billCode);
		// 根据billCode查询带付款编号
		String refundCode = codeService.generateRefundCode(billCode);

		ViewContext.put("vo", entity);
		ViewContext.put("code", refundCode);
		return HtmlRestResult.popHtmlFragment("afterloan/payment_print");
	}
}
